package com.volcreate.week2_3.no11;

/**
 * @author zxc
 * @date 2020/9/23
 */
public class Main {
    public static void main(String[] args) {
        Oval oval = new Oval(8.0, 6.0);
        System.out.println("The area of " + oval + " is " + oval.area());
        System.out.println("The perimeterof " + oval + " is " + oval.perimeter());
    }
}

abstract class Shape {
    static final double PI = 3.1415926;

    abstract double area();

    abstract double perimeter();
}

class Oval extends Shape {
    private double a;
    private double b;

    public Oval(double a, double b) {
        this.a = a;
        this.b = b;
    }

    public Oval() {
    }

    @Override
    double area() {
        return PI * a * b;
    }

    @Override
    double perimeter() {
//        return 2 * PI * b + 4 * (a - b);
        return 2 * PI * Math.sqrt((a * a + b * b) / 2);
    }

    @Override
    public String toString() {
        return "Oval(a:" + a + ",b:" + b + ")";
    }
}
